/*=============================================================================
#    The element-comm is a tentative program used to test our ideas.           
#                       Copyright (C)  bgao                                    
#
#     This program is free software; you can redistribute it and/or            
#      modify it under the terms of the GNU General Public License             
#     as published by the Free Software Foundation; either version 2           
#         of the License, or (at your option) any later version.               
#
#     This program is distributed in the hope that it will be useful,          
#    but WITHOUT ANY WARRANTY; without even the implied warranty of           
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            
#             GNU General Public License for more details.                    
#
#    You should have received a copy of the GNU General Public License        
#     along with this program; if not, write to the Free Software             
#      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,             
#                       MA  02110-1301, USA.                                  
#==============================================================================
# $Id: list.h 348 2010-11-29 09:01:16Z bgao $ 
#
# $Author: bgao $ 
#
# $Revision: 348 $ 
#
# $Date: 2010-11-29 17:01:16 +0800 (星期一, 29 十一月 2010) $ 
#
# Description: 
#
=============================================================================*/
/*! @file list.h
 *  @brief This is the interface of the list module
 */
#ifndef _LIST_H_
#define _LIST_H_

/*! concatenate two string pointed by s1 and s2 */
#define CONCAT(s1, s2) s1##s2

/*! the LIST status */
#define LIST_ERR -1
#define LIST_OK  0
#define LIST_EMP -2

/*! define NULL if not defined previously */
#ifndef NULL
#define NULL (void *)0
#endif

/*! define bool type if not defined previously */
#ifndef bool
#define bool unsigned char
#endif

#ifndef _bool
#define _bool
enum _bool {
    true = 1,
    false = 0
};
#endif

/*! define the basic list item */
typedef struct list_item {
    struct list_item *next;
} list_item_t;

/*! define the type, which is a pointer to the header of the list */
typedef void ** list_t;

/*! a macro used to define an instant of type list */
#define LIST(name) \
        list_item_t *CONCAT(name, _head); \
        list_t name = (list_t)&CONCAT(name, _head)

char list_init(list_t list);
char list_add_head(list_t list, void *item);
void *list_get_head(list_t list);
void *list_get_tail(list_t list);
char list_add_tail(list_t list, void *item);
bool list_is_empty(list_t list);
short list_get_length(list_t list);
void *list_del(list_t list, void *item);
void *list_del_head(list_t list);

#endif /* _LIST_H_ */
